package com.example.it.looker.view.activity;

import android.Manifest;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.example.it.looker.R;
import com.example.it.looker.utils.FragmentUtil;
import com.example.it.looker.view.BaseActivity;
import com.example.it.looker.view.fragment.NewsFragment;

public class HomeActivity extends BaseActivity implements FragmentUtil.CreateFragmentCallBack {

    private Toolbar toolbar;
    private BottomNavigationBar navigationBar;

    @Override
    public void initFindView() {
        toolbar = (Toolbar) this.findViewById(R.id.bar);

        navigationBar = (BottomNavigationBar) this.findViewById(R.id.bottomNav);
    }

    @Override
    public void initActvity(Bundle savedInstanceState) {
        setContentView(R.layout.activity_home);
    }

    @Override
    public void init() {
        //初始化ActionBar
        toolbar.setTitle("");
        this.setSupportActionBar(toolbar);
        ActionBar actionBar = this.getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeAsUpIndicator(R.drawable.menu);

        //初始化ButtonNavigation
        navigationBar.setMode(BottomNavigationBar.MODE_FIXED);

        //添加Item
        navigationBar.addItem(new BottomNavigationItem(R.drawable.news, "新闻").setActiveColorResource(R.color.colorAccent));
        navigationBar.addItem(new BottomNavigationItem(R.drawable.image, "美图").setActiveColorResource(R.color.colorAccent));
        navigationBar.addItem(new BottomNavigationItem(R.drawable.video, "视频").setActiveColorResource(R.color.colorAccent));
        navigationBar.addItem(new BottomNavigationItem(R.drawable.more, "关于").setActiveColorResource(R.color.colorAccent));

        //初始化navigationBar
        navigationBar.initialise();

        //为底部导航栏注册点击事件
        navigationBar.setTabSelectedListener(new BottomNavigationBar.SimpleOnTabSelectedListener() {
            @Override
            public void onTabSelected(int position) {
                FragmentUtil.showFragmetn(getSupportFragmentManager().beginTransaction(), position, HomeActivity.this);
            }
        });

        FragmentUtil.showFragmetn(getSupportFragmentManager().beginTransaction(), 0, HomeActivity.this);
    }

    /**
     * 创建碎片
     */
    @Override
    public Fragment CreateFragment(int position) {
        Fragment fragment = null;
        switch (position) {
            case 0:
                fragment = new NewsFragment();
                break;
        }
        return fragment;
    }
}
